package org.pine.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Direct策略配置
 * @author liucs
 */
@Configuration
public class RabbitDirectConfig {
    public final static String DIRECT_NAME = "pine-direct";
    @Bean
    Queue queue() {
        return new Queue("hello-queue");
    }
    @Bean
    DirectExchange directExchange() {
        //3个参数：名字，重启后是否依然有效，长期未使用是否删除
        return new DirectExchange(DIRECT_NAME, true, false);
    }

    /**
     * 将Exchange和Queue绑定在一起
     * @return Binding 对象
     */
    @Bean
    Binding binding() {
        return BindingBuilder.bind(queue())
                .to(directExchange()).with("direct");
    }
}
